package com.cos.consumer.services;

import com.cos.common.entity.Student;
import com.cos.consumer.feign.SupplierFeignClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheKey;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;

/**
 * @author: COS
 * @time: 2022/4/29 11:26
 * @description:
 */
@Service
public class SupplierServices {
    //在这个业务层调用feign
    @Autowired
    private SupplierFeignClient feignClient;
    //缓存结果
    @CacheResult
    @HystrixCommand(commandKey = "findById")
    public Student findDate2(@CacheKey Integer id){
        Student studentById = feignClient.getStudentById(id);
        return studentById;
    }
    @CacheRemove(commandKey = "findById")
    @HystrixCommand
    public void clearFindById(@CacheKey Integer id){
        System.out.println("findById被清空");
    }
}
